package net.sxnic.jhitem.itemoperation.action;

import java.util.*;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.sxinfo.core.dao.hibernate3.HibernateCriteria;
import net.sxinfo.core.dao.hibernate3.HibernateDaoUtils;
import net.sxinfo.core.dao.hibernate3.HibernateOrder;
import net.sxinfo.core.util.WebUtils;
import net.sxnic.comm.utils.PropertyUtil;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

/**
 * @Description: [一句话描述该类的功能]
 * @Author [姓名] [联系方式]
 * @CreateDate:
 * @UpdateDate:
 * @Version 1.0
 */
public class Browse extends ItemOperationAction {

	private static final long serialVersionUID = 2185256159950914822L;
	private static Logger logger = LoggerFactory.getLogger(Browse.class);

	private String queryItemCode;
	private String queryItemName;

	public String execute() throws Exception {

		try {
			// 设置页码
			int pageNumber = WebUtils.getPageNumber(request);
			// 设置每页显示条数
			int pageSize = PropertyUtil.findTableSize("firstbrowse.tabsize");
			// 设置排序（默认ID）
			HibernateOrder infoCodeOrder = HibernateDaoUtils
					.createHibernateOrder("id", true);
			// 设置查询条件
			HibernateCriteria hc = new HibernateCriteria().add(infoCodeOrder);
			// 按XX条件查询示例
			Criterion dc = null;
			if (StringUtils.isNotBlank(queryItemCode)) {
				dc = Restrictions.eq("soperCode", queryItemCode);
				hc.add(dc);
			}
			if (StringUtils.isNotBlank(queryItemName)) {
				dc = Restrictions
						.ilike("soperName", "%"+queryItemName+"%");
				hc.add(dc);
			}

			itemOperations = itemOperationManager.getPageByCriteria(pageNumber,
					pageSize, hc);
			logger.debug("查询成功");
		} catch (Exception e) {
			e.printStackTrace();
		}

		return SUCCESS;
	}

	public String getQueryItemCode() {
		return queryItemCode;
	}

	public void setQueryItemCode(String queryItemCode) {
		this.queryItemCode = queryItemCode;
	}

	public String getQueryItemName() {
		return queryItemName;
	}

	public void setQueryItemName(String queryItemName) {
		this.queryItemName = queryItemName;
	}

}
